package com.knife.message.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.knife.cache.redis.constants.RedisConstant;
import com.knife.message.domain.entity.KnifeMessageTemplate;
import com.knife.message.infra.cache.v2.KnifeMessageTemplateCache;
import com.knife.message.infra.mapper.KnifeMessageTemplateMapper;
import com.knife.redis.KnifeRedisHelper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author tianhao.luo@hand-china.com
 * @version 1.0
 * @date 2021年11月22日 星期一 11:45 上午
 * @description
 * @since 1.0
 */
@Configuration("KnifeMessageRedisCacheConfigure")
public class KnifeMessageRedisCacheConfigure {
    @Resource
    private ObjectMapper objectMapper;
    @Resource
    private KnifeRedisHelper knifeRedisHelper;
    @Resource
    private KnifeMessageTemplateMapper knifeMessageTemplateMapper;


    @Bean
    public KnifeMessageTemplateCache knifeMessageTemplateCache() {
        return new KnifeMessageTemplateCache(1,
                RedisConstant.MESSAGE + ":" + "messageTemplateCache",
                () -> knifeMessageTemplateMapper.selectList(null),
                KnifeMessageTemplate::getCode,
                knifeRedisHelper,
                objectMapper
        );
    }

}
